home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Hello / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.2 KB  |  259 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                HelloFrm.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Hello.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- Framework Layer -----
  29.  
  30. #ifndef FWCONTXT_H
  31. #include "FWContxt.h"
  32. #endif
  33.  
  34. #ifndef FWUTIL_H
  35. #include "FWUtil.h"
  36. #endif
  37.  
  38. #ifndef FWPRESEN_H
  39. #include "FWPresen.h"
  40. #endif
  41.  
  42. #ifndef FWSELECT_H
  43. #include "FWSelect.h"
  44. #endif
  45.  
  46. #ifndef FWGROWBX_H
  47. #include "FWGrowBx.h"
  48. #endif
  49.  
  50. #ifndef FWSCLBAR_H
  51. #include "FWSclBar.h"
  52. #endif
  53.  
  54. // ----- OS Layer -----
  55.  
  56. #ifndef FWMENU_H
  57. #include "FWMenu.h"
  58. #endif
  59.  
  60. #ifndef FWEVENT_H
  61. #include "FWEvent.h"
  62. #endif
  63.  
  64. #ifndef FWALERT_H
  65. #include "FWAlert.h"
  66. #endif
  67.  
  68. // ----- Graphic Includes -----
  69.  
  70. #ifndef FWRECT_H
  71. #include "FWRect.h"
  72. #endif
  73.  
  74. #ifndef FWTXTBOX_H
  75. #include "FWTxtBox.h"
  76. #endif
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_StdProps_defined
  85. #include <StdProps.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODDragItemIterator_xh
  89. #include <DgItmIt.xh>
  90. #endif
  91.  
  92. //========================================================================================
  93. // Runtime Information
  94. //========================================================================================
  95.  
  96. #ifdef FW_BUILD_MAC
  97. #pragma segment odfhello
  98. #endif
  99.  
  100. FW_DEFINE_AUTO(CHelloFrame)
  101.  
  102. //========================================================================================
  103. // CHelloFrame class
  104. //========================================================================================
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // CHelloFrame constructor
  108. //----------------------------------------------------------------------------------------
  109. CHelloFrame::CHelloFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CHelloContent* content) :
  110.     FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  111.     FW_MDraggableFrame(ev, this),
  112.     FW_MDroppableFrame(ev, this),    
  113.     fHelloContent(content)
  114. {
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // CHelloFrame destructor
  119. //----------------------------------------------------------------------------------------
  120.  
  121. CHelloFrame::~CHelloFrame()
  122. {
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    CHelloFrame::DoMouseDown
  127. //----------------------------------------------------------------------------------------
  128.  
  129. FW_Handled CHelloFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  130. {
  131.     FW_Handled result = FW_kNotHandled;
  132.  
  133.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE) &&
  134.        this->Drag(ev, theMouseEvent)) 
  135.     {
  136.         result = FW_kHandled;
  137.     }
  138.  
  139.     return result;
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // CHelloFrame::DoAdjustMenus
  144. //----------------------------------------------------------------------------------------
  145.  
  146. FW_Handled CHelloFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  147.                                       FW_Boolean hasMenuFocus,
  148.                                       FW_Boolean isRoot)    // Override
  149. {
  150. FW_UNUSED(isRoot);
  151.     if (hasMenuFocus)
  152.         menuBar->EnableCommand(ev, kODCommandPaste, HasSupportedKindOnClipboard(ev));
  153.     
  154.     return FW_kNotHandled;
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. // CHelloFrame::Draw
  159. //----------------------------------------------------------------------------------------
  160.  
  161. void CHelloFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  162. {
  163.     FW_CViewContext fc(ev, this, odFacet, invalidShape);
  164.     FW_CRect invalidRect;
  165.     fc.GetClipRect(invalidRect);
  166.  
  167.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  168.  
  169.     FW_CRect helloRect = GetBounds(ev);
  170.  
  171.     FW_CRectShape::RenderRect(fc, helloRect, FW_kFrame, FW_CInk(FW_kRGBBlack));
  172.  
  173.     // If this is a root part, draw the text centered horizontally and vertically.
  174.     // If it's an embedded part, center the text horizontally, with word wrap and clipping.
  175.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxJustifyVCenter;
  176.     if (!fHelloContent->IsTextCentered())
  177.     {
  178.         options |= FW_kTextBoxWordWrap;
  179.         options |= FW_kTextBoxClipToBox;
  180.     }
  181.     FW_CTextBoxShape::RenderTextBox(
  182.         fc,
  183.         fHelloContent->GetTextData(),
  184.         helloRect,
  185.         FW_kSystemFont,
  186.         options);
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // CHelloFrame::FrameShapeChanged
  191. //----------------------------------------------------------------------------------------
  192. // By default a FW_CFrame view is not refreshed entirely when resized.
  193. // You must decide if your content's appearance depends on the frame's size.
  194. // If it doesn't you don't need to override FrameShapeChanged().
  195. // Here we must redraw the whole frame everytime because the text is centered.
  196.  
  197. void CHelloFrame::FrameShapeChanged(Environment* ev)
  198. {
  199.     FW_CFrame::FrameShapeChanged(ev);
  200.     
  201.     this->Invalidate(ev);
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. //    CHelloFrame::NewClipboardCommand
  206. //----------------------------------------------------------------------------------------
  207.  
  208. FW_CClipboardCommand* CHelloFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  209. {
  210.     return FW_NEW(CHelloEditCommand, (ev, commandID, fHelloContent, this));
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    CHelloFrame::NewDragCommand
  215. //----------------------------------------------------------------------------------------
  216.  
  217. FW_CDragCommand* CHelloFrame::NewDragCommand(Environment *ev, 
  218.                                             FW_CFrame* theFrame,
  219.                                             const FW_CMouseEvent& theMouseEvent)
  220. {
  221. FW_UNUSED(theMouseEvent);
  222.     return FW_NEW(CHelloDragCommand, (ev, fHelloContent, theFrame));
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //    CHelloFrame::NewDropCommand
  227. //----------------------------------------------------------------------------------------
  228.  
  229. FW_CDropCommand* CHelloFrame::NewDropCommand(Environment* ev,
  230.                                              FW_CFrame* frame,
  231.                                              ODDragItemIterator* dropInfo, 
  232.                                              ODFacet* odFacet, 
  233.                                              const FW_CPoint& dropPoint)
  234. {
  235. FW_UNUSED(frame);
  236.     return FW_NEW(CHelloDropCommand, (ev, fHelloContent, this, dropInfo, odFacet, dropPoint));
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //     CHelloFrame::CreateSubViews
  241. //----------------------------------------------------------------------------------------
  242.  
  243. void CHelloFrame::CreateSubViews(Environment* ev)
  244. {        
  245.     // Create a GrowBox only in root frame
  246.     // Note: you do not need CreateSubViews if the views are defined in resources.
  247.     //        See the Container or Form samples.
  248.     
  249.     if (this->IsRoot(ev)) 
  250.     {
  251.         FW_CRect frameRect = GetBounds(ev);  
  252.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  253.         frameRect.right -= sbSize.x;
  254.         frameRect.bottom -= sbSize.y;
  255.         
  256.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  257.     }
  258. }
  259.